import cn.hutool.core.util.StrUtil;
import global.InitCache;
import load.InitLoad;
import log.LogInfo;
import netty.Client;

/**
 * @author zhouwz
 * @date 2020/11/3 13:33
 */
public class HikApplication {

    public static void main(String[] args) throws Exception {
        validateArgs(args);
        InitLoad.mapInfoLoad();
        LogInfo.baseInfo("地图数据加载完成...");
        InitLoad.vehicleStatusLoad();
        LogInfo.baseInfo(StrUtil.format("车辆: {} IP: {} 信息加载完成:{}", args[0], args[1], InitCache.realtimeStatus));
        Client.startNettyClient();
    }

    /**
     * 校验入参
     *
     * @param args 入参
     */
    private static void validateArgs(String[] args) throws Exception {
        String notice = "请输入车辆编号、地图数据文件路径&名称、netty客户端IP、netty客户端端口、netty服务端IP!!(请注意顺序)";
        int argLen = 5;
        if (args.length == 0) {
            throw new Exception(notice);
        }
        if (args.length == argLen) {
            InitCache.vehicleCodeInt = Integer.parseInt(args[0]);
            InitCache.pathAndFilename = args[1];
            InitCache.nettyClientIp = args[2];
            InitCache.nettyClientPort = Integer.parseInt(args[3]);
            InitCache.nettyServerIp = args[4];
        } else {
            throw new Exception("参数输入不全!!" + notice);
        }
    }
}